//
//  CharacterStepPublishViewController.swift
//  SkylowAPP
//
//  Created by 青色石头 on 2024/9/21.
//

import UIKit
import YYText
import SnapKit

class CharacterStepPublishViewController: UIViewController {
    
    @IBOutlet weak var memberCountL: UILabel!
    

    @IBOutlet weak var protocolStack: UIStackView!
    
    @IBOutlet weak var headerImg: UIImageView!
    private lazy var protocolLbl = {
        
        let string = "I read and agree with the Terms and Privacy Policy."

        let attributes = [NSAttributedString.Key.font: UIFont.regular(14), NSAttributedString.Key.foregroundColor: UIColor.white]
        let attr = NSMutableAttributedString(string: string, attributes: attributes)
        attr.yy_maximumLineHeight = 22
        attr.yy_minimumLineHeight = 22
        let x = 48 / 430.0 * kScreenWidth
        let height = attr.boundingRect(with: CGSize(width: kScreenWidth - x * 2 - 24 - 12, height: CGFloat.greatestFiniteMagnitude), options: [.usesLineFragmentOrigin, .usesFontLeading], context: nil).height
        
        attr.yy_setTextHighlight(NSRange(location: 26, length: 5), color: .colorWith(hexString: "#B24592"), backgroundColor: .clear) { [unowned self] (_, _, _, _) in
            print("====")
        }
        attr.yy_setTextHighlight(NSRange(location: 36, length: 14), color: .colorWith(hexString: "#B24592"), backgroundColor: .clear) { [unowned self] (_, _, _, _) in
            print("====")
        }
        
        let lbl = YYLabel()
        lbl.numberOfLines = 0
        lbl.attributedText = attr
        lbl.font = .regular(14)
        self.protocolStack.addArrangedSubview(lbl)
        // YYlabel必须知道高度才会换行。
        lbl.snp.makeConstraints { make in
            make.height.equalTo(height)
        }
        return lbl
    }()
    
    override func viewDidLoad() {
        super.viewDidLoad()
        memberCountL.layer.cornerRadius = 19
        memberCountL.layer.masksToBounds = true
        _ = protocolLbl
    }


    override func viewDidLayoutSubviews() {
        super.viewDidLayoutSubviews()
        headerImg.layer.cornerRadius = headerImg.height / 2
    }
}
